package com.lili.math;

/**
 * @Auther: 李 力
 * @Date: 2024/8/1
 * @Description: 七进制数
 * @version: 1.0
 */
public class LeetCode504 {

    /*
     * 时间复杂度: O(log|num|)
     * 空间复杂度: O(log|num|)
     */
    public String convertToBase7(int num) {
        if (num == 0) {
            return "0";
        }
        boolean flag = num < 0;
        num = Math.abs(num);
        StringBuffer stringBuffer = new StringBuffer();
        while (num > 0) {
            stringBuffer.append(num % 7);
            num = num / 7;
        }
        String str = stringBuffer.reverse().toString();
        if (flag) {
            str = "-" + str;
        }
        return str;
    }
}
